import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue(), vueJsx(), vueDevTools()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    port: 5173,
    open: false,
    cors: true,
    hmr: {
      overlay: false,
    },
    proxy: {
      // 基本代理示例
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
      // WebSocket代理示例
      '/socket.io': {
        target: 'ws://localhost:8080',
        ws: true,
      },
      // 更复杂的路径重写示例
      '/service': {
        target: 'http://backend-service',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/service/, '/api'),
      },
    },
  },
})
// import { defineConfig } from 'vite'
// import vue from '@vitejs/plugin-vue'
// export default defineConfig({ plugins: [vue()] })
